/*
 *    Copyright 2011-2020 enniu.com
 */
<#if localPackage?? && localPackage!="">
package ${localPackage}.dao.impl;
</#if>
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

<#list importPackages as package>
import ${package}.*;
 </#list>

/**
* ${model.description}
*
* @author ${author} ${date}
* <#if email?? && email!="">E-mail:${email}</#if>
*/
@Repository
public class ${XxxDaoImpl}{

    @Autowired
    private SqlSession ${sqlSession};

    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_INSERT = "${XxxDao}.insert";
    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_UPDATE = "${XxxDao}.update";
    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_DELETE = "${XxxDao}.deleteBy${Id}";
    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_BY_ID = "${XxxDao}.selectBy${Id}";
    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_COUNT = "${XxxDao}.selectCount";
    private static final String SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_LIST = "${XxxDao}.selectList";


    /**
     *@param ${xxxBean}
     * 增加
     */
	public int insert(${XxxBean} ${xxxBean}){
        return ${sqlSession}.insert(SQL_${NameConvert.convert2UpperName(tableName)}_INSERT, ${xxxBean});
	}
	
    /**
     * 更新
     * @param ${xxxBean}
     * @return
     */
	public int update(${XxxBean} ${xxxBean}) {
        return ${sqlSession}.update(SQL_${NameConvert.convert2UpperName(tableName)}_UPDATE,${xxxBean});
	}
	
	/**
     * 根据主键删除
	 * @param ${id}
	 */
	public int deleteBy${Id}(${DataTypeAdapt.convert(model.keyProperty.clazzType)} ${id}) {
        return ${sqlSession}.delete(SQL_${NameConvert.convert2UpperName(tableName)}_DELETE,${id});
	}
	
    /**
     * 根据主键查询
     * @param ${id}
     * @return
     */
	public ${XxxBean} selectBy${Id}(${DataTypeAdapt.convert(model.keyProperty.clazzType)} ${id}) {
        return (${XxxBean})${sqlSession}.selectOne(SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_BY_ID,${id});
	}

    /**
     * 获取符合条件的总数目
     */
    public int selectCount(${XxxBean} ${xxxBean}){
        return ${sqlSession}.selectOne(SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_COUNT,${xxxBean});
    }

    /**
     * 获取分页的数据
     */
    public List<${XxxBean}> selectList(${XxxBean} ${xxxBean},int startIndex,int limit){
        Map<String,Object> params = new HashMap<String,Object>();
        <#list model.properties as property>
        params.put("${property.propertyName}",${xxxBean}.get${TableNameConvert.convert4ClassName(property.propertyName)}());
        </#list>
        params.put("startIndex",startIndex);
        params.put("limit",limit);
        List<${XxxBean}> list = ${sqlSession}.selectList(SQL_${NameConvert.convert2UpperName(tableName)}_SELECT_LIST,params);
        return list;
    }
}